$(function() {
    var orderId = "0";
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == "orderId"){ orderId = pair[1];}
    }
    console.log(orderId);
    var editOrderInfo = new Vue({
        el:"#editOrderInfo",
        data:{
            patientsName:"",
            patiensPhone:"",
            identityCard:"",
            patientsSex:"",
            nation:"",
            orderSratus:"",
            patientsTime:"",
            price:"",
            hospitalName:"",
            departmentName:"",
            doctorName:"",
            orderId:""
        },
        methods:{
            pay:function (){
                var that = this;
                location.href = "../alipay/pay?WIDout_trade_no="+that.orderId+"&WIDsubject=挂号预约&WIDtotal_amount="+that.price+"&WIDbody="+that.hospitalName+"预约";
            },
            cancleOrderInfo:function () {
                alert(this.orderId)
                var that = this;
                axios.post("../api/order/cancelOrder",{
                    orderid:that.orderId
                }).then(function(response){
                    if (response.data.code!="0"){
                        alert(response.data.msg)
                        return;
                    }
                    alert("取消预约成功")
                    //console.log(response.data);
                }).catch(function(err){
                    console.log(err);
                });
            },
            getOrderInfo:function () {
                var that = this;
                axios.get("../api/order/getOrderByOrderId?orderId="+orderId).then(function(response){
                    that.patientsName = response.data.data.patientsName;
                    that.patiensPhone = response.data.data.patiensPhone;
                    that.identityCard = response.data.data.identityCard;
                    if (response.data.data.patientsSex!=1){
                        that.patientsSex = "女";
                    }else{
                        that.patientsSex = "男";
                    }
                    that.nation = response.data.data.nation;
                    that.orderSratus = response.data.data.orderSratus;
                    that.patientsTime = response.data.data.patientsTime;
                    that.price = response.data.data.price;
                    that.hospitalName = response.data.data.hospitalName;
                    that.departmentName = response.data.data.departmentName;
                    that.doctorName = response.data.data.doctorName;
                    that.orderId = response.data.data.orderId;
                }).catch(function(err){
                    console.log(err);
                });
            },
            refund:function () {
                var that = this;
                axios.post("../alipay/alipayRefund",{
                    WIDTRout_trade_no:that.orderId,
                    WIDTRout_request_no:that.orderId,
                    WIDTRrefund_amount:that.price,
                    WIDTRrefund_reason:"取消挂号预约"
                }).then(function(response){
                    console.log(response)
                    console.log(response.data.data.alipay_trade_refund_response.code);
                    if (response.data.data.code!="0"){
                        alert("退款失败，请联系客服处理");
                    }else{
                        alert("取消预约、退款成功");
                        location.href="my_reservation.html"
                    }
                }).catch(function(err){
                    console.log(err);
                });
            },
            downloadWord:function () {
                location.href = "../api/file/downloadReport?orderId="+orderId;
            }
        },
        created(){
            this.getOrderInfo();
        }
    })
    var getTokenVue = new Vue({
        el:"#getToken",
        data:{
            token:localStorage.getItem("token")
        }
        ,methods:{

        }
    })
})